<?php
class ControllerWebIndex extends Controller {
	private $error = array ();
	public function index() {
		$this->load->language ( 'web/index' );
		
		$this->document->setTitle ( $this->language->get ( 'heading_title' ) );
		
		$this->data ['heading_title'] = $this->language->get ( 'heading_title' );
		$this->data ['button_save'] = $this->language->get ( 'button_save' );
		$this->data ['button_cancel'] = $this->language->get ( 'button_cancel' );
		$this->data ['gobal_setting'] = $this->language->get ( 'gobal_setting' );
		$this->data ['index_setting'] = $this->language->get ( 'index_setting' );
		$this->data ['left_setting'] = $this->language->get ( 'left_setting' );
		$this->data ['shop_reason'] = $this->language->get ( 'shop_reason' );
		$this->data ['text_blog_num'] = $this->language->get ( 'text_blog_num' );
		$this->data['text_image_manager'] = $this->language->get('text_image_manager');
		
		if (isset ( $this->error ['warning'] )) {
			$this->data ['error_warning'] = $this->error ['warning'];
		} else {
			$this->data ['error_warning'] = '';
		}
		
		if (isset ( $this->error ['name'] )) {
			$this->data ['error_name'] = $this->error ['name'];
		} else {
			$this->data ['error_name'] = array ();
		}
		
		if (isset ( $this->error ['meta_description'] )) {
			$this->data ['error_meta_description'] = $this->error ['meta_description'];
		} else {
			$this->data ['error_meta_description'] = array ();
		}
		
		if (isset ( $this->error ['description'] )) {
			$this->data ['error_description'] = $this->error ['description'];
		} else {
			$this->data ['error_description'] = array ();
		}
		
		if (isset ( $this->error ['model'] )) {
			$this->data ['error_model'] = $this->error ['model'];
		} else {
			$this->data ['error_model'] = '';
		}
		
		if (isset ( $this->error ['date_available'] )) {
			$this->data ['error_date_available'] = $this->error ['date_available'];
		} else {
			$this->data ['error_date_available'] = '';
		}
		if (isset ( $this->session->data ['success'] )) {
			$this->data ['success'] = $this->session->data ['success'];
			
			unset ( $this->session->data ['success'] );
		} else {
			$this->data ['success'] = '';
		}
		
		$url = '';
		
		if (isset ( $this->request->get ['filter_name'] )) {
			$url .= '&filter_name=' . urlencode ( html_entity_decode ( $this->request->get ['filter_name'], ENT_QUOTES, 'UTF-8' ) );
		}
		
		if (isset ( $this->request->get ['filter_model'] )) {
			$url .= '&filter_model=' . urlencode ( html_entity_decode ( $this->request->get ['filter_model'], ENT_QUOTES, 'UTF-8' ) );
		}
		
		if (isset ( $this->request->get ['filter_price'] )) {
			$url .= '&filter_price=' . $this->request->get ['filter_price'];
		}
		
		if (isset ( $this->request->get ['filter_quantity'] )) {
			$url .= '&filter_quantity=' . $this->request->get ['filter_quantity'];
		}
		
		if (isset ( $this->request->get ['filter_status'] )) {
			$url .= '&filter_status=' . $this->request->get ['filter_status'];
		}
		
		if (isset ( $this->request->get ['sort'] )) {
			$url .= '&sort=' . $this->request->get ['sort'];
		}
		
		if (isset ( $this->request->get ['order'] )) {
			$url .= '&order=' . $this->request->get ['order'];
		}
		
		if (isset ( $this->request->get ['page'] )) {
			$url .= '&page=' . $this->request->get ['page'];
		}
		$this->data ['breadcrumbs'] = array ();
		
		$this->data ['breadcrumbs'] [] = array (
				'text' => $this->language->get ( 'text_home' ),
				'href' => $this->url->link ( 'common/home', 'token=' . $this->session->data ['token'], 'SSL' ),
				'separator' => false 
		);
		
		$this->data ['breadcrumbs'] [] = array (
				'text' => $this->language->get ( 'heading_title' ),
				'href' => $this->url->link ( 'web/index', 'token=' . $this->session->data ['token'] . $url, 'SSL' ),
				'separator' => ' :: ' 
		);
		
		$this->data ['token'] = $this->session->data ['token'];
		
		$this->data ['action'] = $this->url->link ( 'web/index/update', 'token=' . $this->session->data ['token'], 'SSL' );
		
		$this->load->model ( 'web/index' );
		$config = $this->model_web_index->getSetting ();
		
		foreach ( $config as $k => $v ) {
			if($v['type']!=4){
				$configs [$v ['type']] [] = $v ['content'];
			}else{
				$configs [$v ['type']] [] = $v;
			}
			
		}
		$this->data ['configs'] = $configs;
		
		$this->template = 'web/index.tpl';
		$this->children = array (
				'common/header',
				'common/footer' 
		);
		
		$this->response->setOutput ( $this->render () );
		/*
		 * $this->load->language('web/index');
		 * $this->document->setTitle($this->language->get('heading_title'));
		 * $this->load->model('catalog/product'); $this->getList();
		 */
	}
	
	public function update() {
		$this->load->language ( 'web/index' );
		
		$this->document->setTitle ( $this->language->get ( 'heading_title' ) );
		
		$this->data ['heading_title'] = $this->language->get ( 'heading_title' );
		$this->data ['button_save'] = $this->language->get ( 'button_save' );
		$this->data ['button_cancel'] = $this->language->get ( 'button_cancel' );
		$this->data ['gobal_setting'] = $this->language->get ( 'gobal_setting' );
		$this->data ['index_setting'] = $this->language->get ( 'index_setting' );
		$this->data ['left_setting'] = $this->language->get ( 'left_setting' );
		$this->data ['shop_reason'] = $this->language->get ( 'shop_reason' );
		
		$this->load->model ( 'web/index' );
		
		$this->model_web_index->editSetting ( $this->request->post );
		$this->oplog->add_log(2);
		$this->session->data ['success'] = $this->language->get ( 'text_success' );
		
		$this->redirect ( $this->url->link ( 'web/index', 'token=' . $this->session->data ['token'], 'SSL' ) );
	
	}
	
	private function validateForm() {
		return true;
	}
}